local sk__fenying = fk.CreateSkill {

  name = "sk__fenying",

  tags = {  },

}



sk__fenying:addEffect(fk.Damaged, {
  name = "sk__fenying",
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(sk__fenying.name) and data.damageType == fk.FireDamage
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, sk__fenying.name)
    if player.dead or target.dead or player:isNude() then return end
    local targets = table.map(table.filter(room:getOtherPlayers(target), function(p2)
      return table.every(room:getOtherPlayers(target), function(p1)
        return target:distanceTo(p1) >= target:distanceTo(p2)
      end)
    end), Util.IdMapper)
    table.insert(targets, target.id)
    local n = player:usedSkillTimes(sk__fenying.name, Player.HistoryTurn)
    room:setPlayerMark(player, "sk__fenying-tmp", {n, targets})
    local success, dat = room:askForUseActiveSkill(player, "sk__fenying_active",
      "#sk__fenying-invoke::"..target.id..":"..n..":"..data.damage, true, nil, false)
    room:setPlayerMark(player, "sk__fenying-tmp", 0)
    if success and dat then
      local to = room:getPlayerById(dat.targets[1])
      room:throwCard(dat.cards, sk__fenying.name, player, player)
      if not to.dead then
        room:damage{
          from = player,
          to = to,
          damage = data.damage,
          damageType = fk.FireDamage,
          skillName = sk__fenying.name,
        }
      end
    end
  end,
})

return sk__fenying